//
//  ZHRentCorporateViewController.m
//  sc-cyan-ios
//
//  Created by lj on 2018/1/6.
//  Copyright © 2018年 greenbuilding. All rights reserved.
//

#import "ZHRentCorporateViewController.h"

#import "ZHRentCorporateTableViewCell.h"
#import "SWSearchNaviView.h"

static NSString *const cellID = @"ZHRentCorporateTableViewCell";

@interface ZHRentCorporateViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSInteger lastSelTag;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *topView;
//顶部导航搜索框
@property (nonatomic, strong) SWSearchNaviView *searchNaviView;

@end

@implementation ZHRentCorporateViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar addSubview:self.searchNaviView];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    [self.searchNaviView removeFromSuperview];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpView];
    
}

/** 导航搜索框 */
- (SWSearchNaviView *)searchNaviView{
    if (!_searchNaviView) {
        _searchNaviView = [[SWSearchNaviView alloc] initWithFrame:self.navigationController.navigationBar.bounds];
        MJWeakSelf
        _searchNaviView.popViewBack = ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        };
        
        _searchNaviView.searchText = ^(NSString *text) {
            //            搜索新数据
            
            
            //            [weakSelf.collectionView reloadData];
        };
        
    }
    return _searchNaviView;
}

- (void)setUpView{
    
    //最新
    UIButton *btn = [self.topView viewWithTag:10];
    lastSelTag = 1;
    [self tagAction:btn];
    
    _tableView.estimatedRowHeight = 44;
    _tableView.rowHeight = UITableViewAutomaticDimension;
    
    
    
}

#pragma mark <UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZHRentCorporateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZHRentCorporateTableViewCell class]) owner:nil options:nil] firstObject];
    }
    
    return cell;
}
- (IBAction)tagAction:(UIButton *)sender {
    
    sender.selected = YES;
    
    if (sender.tag != lastSelTag) {
        
        UIButton *lastBtn = [self.topView viewWithTag:lastSelTag];
        lastBtn.selected = NO;
        lastSelTag = sender.tag;
    }
}

@end
